//
//  TTHMHomeToolBar.swift
//  WeiBo
//
//  Created by 涂永江 on 2017/6/8.
//  Copyright © 2017年 涂永江. All rights reserved.
//

import UIKit

class TTHMHomeToolBar: UIView {

    var stusModel:TTStatuesViewModel?{
    
        didSet{
        
            guard let currentModel = stusModel else {
             return
            }
            
//            retweetButton.setTitle("\(currentModel.statues?.reposts_count ?? 0)", for: .normal)
             retweetButton.setTitle(currentModel.reposts_count, for: .normal)
//            commentButton.setTitle("\(currentModel.statues?.comments_count ?? 0)", for: .normal)
              commentButton.setTitle(currentModel.comments_count, for: .normal)
//            unlikeButton.setTitle("\(currentModel.statues?.attitudes_count ?? 0)", for: .normal)
              unlikeButton.setTitle(currentModel.attitudes_count, for: .normal)
        }
    
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var retweetButton:UIButton!
    var commentButton:UIButton!
    var unlikeButton:UIButton!
    func setUI()
    {
    
        //  转发按钮
       retweetButton = createButton(title: "转发", imageName: "timeline_icon_retweet")
        //  评论按钮
       commentButton = createButton(title: "评论", imageName: "timeline_icon_comment")
        //  赞
       unlikeButton = createButton(title: "赞", imageName: "timeline_icon_unlike")
        
        //  第一条线
        let firstLineView = createLineView()
        //  第二条线
        let secondLineView = createLineView()
        
        addSubview(retweetButton)
        addSubview(commentButton)
        addSubview(unlikeButton)
        addSubview(firstLineView)
        addSubview(secondLineView)
        
        retweetButton.snp.makeConstraints { (make) in
            make.top.leading.bottom.equalTo(self)
            make.width.equalTo(commentButton)
        }
        commentButton.snp.makeConstraints { (make) in
            make.top.bottom.equalTo(retweetButton)
            make.leading.equalTo(retweetButton.snp.trailing)
            make.width.equalTo(unlikeButton)
        }
    
        unlikeButton.snp.makeConstraints { (make) in
            make.bottom.top.trailing.equalTo(self)
            make.leading.equalTo(commentButton.snp.trailing)
        }
        firstLineView.snp.makeConstraints { (make) in
            make.centerX.equalTo(retweetButton.snp.trailing)
            make.centerY.equalTo(self)
        }
        secondLineView.snp.makeConstraints { (make) in
            make.centerX.equalTo(commentButton.snp.trailing)
            make.centerY.equalTo(self)
        }
    }
    
    //  创建子按钮
    private func createButton(title: String, imageName: String) -> UIButton {
        let button = UIButton()
        button.setTitle(title, for: .normal)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setImage(UIImage(named: imageName), for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.adjustsImageWhenHighlighted = false
        //  设置背景图片
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), for: .normal)
        return button
    }
    //  创建竖线
    private func createLineView() -> UIImageView {
        let imageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        return imageView
    }
}
